<template>
  <div class="">
    <x-header class="header" :left-options="{backText: ''}">{{goodsType.name}}</x-header>
    <div class="content">
      <ul>

        <li v-for="(x,i) of items" :key="i" :style="{color:x.color}" class="ub pad my-item" @click="handleGoodsType(x)">
          <div style="width:100px;">
            <x-circle :percent="x.cur_count*100/x.in_count" :stroke-width="6" :trail-width="6" :stroke-color="strokeColor2" trail-color="#ececec">
              <span :style="{color: strokeColor2}">{{x.cur_count|int}}{{x.unit}}</span>
            </x-circle>
          </div>
          <div class="title uf-1 ub-v">
            <div>{{x.goodstype_code}} </div>
            <div v-html="x.goodstype_name"></div>
            <div class="">单价 ￥{{x.single_price|money}}</div>
            <div class="btn" @click="handleTrace(x.qrcode_code)">追 溯</div>
          </div>
          <div class="ub uc">
            <!-- <x-button plain type="primary" style="border-radius:20px;">primary</x-button> -->
          </div>

        </li>
      </ul>
    </div>

    <div v-transfer-dom>
      <x-dialog v-model="showScrollBox" class="dialog-demo">
        <div class="dialog-title" v-if="info">
          <div v-html="info.goodstype_descp" class="line-text-1"></div>
        </div>
        <div class="timeline-demo" style="" v-if="info">
          <timeline>
            <timeline-item>
              <h4 class="">{{info.order_type_descp}}入库 {{info.in_count}}{{info.unit}}</h4>
              <p class="">{{info.createtime}}</p>
            </timeline-item>

          </timeline>
          <timeline v-for="y of info.requireInfo" :key="y.order_code">
            <timeline-item>
              <h4 class="">【{{y.realname}}】 提出需求 {{y.ready_out_count|fix(2)}}{{info.unit}}</h4>
              <p class="">{{y.createtime}}</p>
            </timeline-item>
            <timeline-item v-for="z of y.outInfo" :key="z.order_code">
              <h4>【{{z.realname}}】 发起出库单</h4>
              <p>{{z.createtime}}</p>
              <div v-if="z.order_status=='over'">
                <h4>【{{z.storer}}】 扫码出库</h4>
                <p>{{z.endtime}}</p>
              </div>
            </timeline-item>
          </timeline>
        </div>
        <div @click="showScrollBox=false">
          <span class="vux-close"></span>
        </div>
      </x-dialog>
    </div>
  </div>
</template>

<script>
import { XHeader, XCircle, XDialog, Timeline, TimelineItem, TransferDomDirective as TransferDom } from 'vux'
import TraceInfo from '@/components/TraceInfo'
export default {
  data() {
    return {
      comp_id:this.$route.params["comp_id"]||2,
      type:this.$route.params["code"]||2,
      goodsType: {},
      items: [],
      strokeColor2: '#3FC7FA',
      showScrollBox: false,
      info: null
    }
  },
  mounted() {
    this.$store.dispatch("store_city_index_storegoods", { comp_id: this.comp_id, type: this.type }).then((resp) => {
      this.items = resp.body.items
      this.goodsType = resp.body.itemMap.goodsType
      console.log(this.goodsType)

    })
  },
  methods: {
    handleGoodsType(item) {

    },
    handleTrace(qrcode_code) {

      this.info = null
      this.$vux.loading.show({
        text: 'Loading'
      })
      this.$store.dispatch("trace_storeGoodsInfo", { qrcode: qrcode_code, level: 1 }).then(resp => {
        this.info = resp.body.itemMap.storeGoodsInfo
        this.showScrollBox = true
        this.$vux.loading.hide()
      })
    }
  },
  components: {
    XHeader, XCircle, XDialog, Timeline, TimelineItem

  },
  directives: {
    TransferDom
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
@import '~vux/src/styles/close';

.dialog-demo {
  .weui-dialog {
    border-radius: 8px;
    padding-bottom: 8px;
  }
  .dialog-title {
    line-height: 30px;
    color: #666;
    margin: 0.2em 2em;
  }
  .img-box {
    height: 350px;
    overflow: hidden;
  }
  .vux-close {
    margin-top: 8px;
    margin-bottom: 8px;
  }
}

li {
  .title {
    padding-left: 20px;
  }
  .sub-title {
    font-size: 0.8em;
  }
  i {
    margin-left: 10px;
  }
  .btn {
    margin-top: 0.2em;
    padding: 0.1em 0.6em 0.3em;
    border: 1px solid #3FC7Ff;
    border-radius: 0.7em;
    width: 3.5em;
    text-align: center;
  }
}

.timeline-demo {
  height: 400px;
  padding: 15px 0;
  overflow: scroll;
  -webkit-overflow-scrolling: touch;
  text-align: left;
  p {
    color: #888;
    font-size: 0.8rem;
  }
  h4 {
    color: #666;
    font-weight: normal;
  }
  .recent {
    color: rgb(4, 190, 2)
  }
}
</style>